package com.cskaoyan.service;

        import com.cskaoyan.bean.*;
        import com.cskaoyan.bean.goods.CatAndBrandVO;
        import com.cskaoyan.bean.goods.GoodsListBO;
        import com.cskaoyan.bean.goods.GoodsListVO;
        import com.cskaoyan.bean.lzp.*;

        import com.cskaoyan.bean.goods.*;
        import com.cskaoyan.bean.params.BaseParam;
        import com.cskaoyan.mapper.*;
        import com.cskaoyan.until.StringUtils;
        import com.github.pagehelper.PageHelper;
        import com.github.pagehelper.PageInfo;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Service;
        import org.springframework.transaction.annotation.Propagation;
        import org.springframework.transaction.annotation.Transactional;

        import java.util.ArrayList;
        import java.util.Date;
        import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    CategoryMapper categoryMapper;
    @Autowired
    BrandMapper brandMapper;
    @Autowired
    GoodsProductMapper goodsProductMapper;
    @Autowired
    GoodsAttributeMapper goodsAttributeMapper;
    @Autowired
    GoodsSpecificationMapper goodsSpecificationMapper;
    @Autowired
    StorageMapper storageMapper;
    @Autowired
    CommentMapper commentMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    IssueMapper issueMapper;
    @Autowired
    CollectMapper collectMapper;

    //TODO：新增一个historyMapper；
    @Autowired
    SearchHistoryMapper historyMapper;

    /**
     * 获取商品列表
     * 涉及表格：goods
     *
     * @param baseParam
     * @param goodsListBO
     * @return
     */

    @Override
    public GoodsListVO queryGoods(BaseParam baseParam, GoodsListBO goodsListBO) {
        GoodsListVO goodsListVO = new GoodsListVO();

        //查询条件及分页设置
        GoodsExample goodsExample = new GoodsExample();
        GoodsExample.Criteria criteria = goodsExample.createCriteria();
        if (goodsListBO.getGoodsId() != null) {
            criteria.andIdEqualTo(goodsListBO.getGoodsId());
        }
        if (!StringUtils.isEmpty(goodsListBO.getGoodsSn())) {
            criteria.andGoodsSnEqualTo(goodsListBO.getGoodsSn());
        }

        if (!StringUtils.isEmpty(goodsListBO.getName())) {
            criteria.andNameLike("%" + goodsListBO.getName() + "%");
        }

//        //PageHelper.startPage(baseParam.getPage(), baseParam.getLimit());
//
//
//        goodsExample.setOrderByClause(baseParam.getSort(), baseParam.getOrder());
//
//        criteria.andDeletedEqualTo(false);
//
////        // 当limit不为0时，开启分页插件，设置查询排序条件
////        if (limit != 0) {
////            PageHelper.startPage(page, limit);
////            example.setOrderByClause(sort + " " + order);
////        } else {// 修改优惠券指定商品时前端发送的请求为limit=0
////            page = 0;
////        }
//
//        PageHelper.startPage(baseParam.getPage(), baseParam.getLimit());

        criteria.andDeletedEqualTo(false);

        if (baseParam.getLimit() != 0) {
            goodsExample.setOrderByClause(baseParam.getSort(), baseParam.getOrder());
            PageHelper.startPage(baseParam.getPage(), baseParam.getLimit());
        }

        //查询goods及查询结果处理
        List<Goods> list = goodsMapper.selectByExample(goodsExample);
        PageInfo<Goods> pageInfo = new PageInfo<>(list);
        Integer pages = pageInfo.getPages();
        long total = pageInfo.getTotal();

        goodsListVO.setLimit(baseParam.getLimit());
        goodsListVO.setList(list);
        if (baseParam.getPage() == null) {
            goodsListVO.setPage(0);
        }
        goodsListVO.setPages(pages);
        goodsListVO.setTotal(total);

        return goodsListVO;
    }


    /**
     * 获取商品分类信息和商品品牌信息
     * 涉及表格：category，brand
     *
     * @return
     */

    @Override
    public CatAndBrandVO queryCategoryAndBrand() {
        CategoryExample categoryExample = new CategoryExample();
        CategoryExample.Criteria criteria = categoryExample.createCriteria();

        //得到category所有一级分类
        criteria.andPidEqualTo(0);
        //criteria.andDeletedEqualTo(true);
        List<Category> categories = categoryMapper.selectByExample(categoryExample);

        List<CatAndBrandVO.CategoryList> categoryList = new ArrayList<>();
        for (Category category : categories) {
            categoryExample.clear();
            Integer id = category.getId();
            criteria.andPidEqualTo(id);
            List<Category> childrenTemps = categoryMapper.selectByExample(categoryExample);
            List<CatAndBrandVO.CategoryList.Category> children = new ArrayList<>();

            for (Category categoryTemp : childrenTemps) {
                children.add(new CatAndBrandVO.CategoryList.Category(categoryTemp.getId(), categoryTemp.getName()));
            }

            categoryList.add(new CatAndBrandVO.CategoryList(id, category.getName(), children));
        }

        //获取brandList
        BrandExample brandExample = new BrandExample();

        List<Brand> brands = brandMapper.selectByExample(brandExample);

        List<CatAndBrandVO.Brand> brandList = new ArrayList<>();
        for (Brand brand : brands) {
            brandList.add(new CatAndBrandVO.Brand(brand.getId(), brand.getName()));
        }

        CatAndBrandVO catAndBrandVO = new CatAndBrandVO();
        catAndBrandVO.setCategoryList(categoryList);
        catAndBrandVO.setBrandList(brandList);

        return catAndBrandVO;
    }


    @Override
    public GoodsWxListVO goodsWxList(GoodsWxListBO goodsWxListBO, Integer id) {

        Integer categoryId = goodsWxListBO.getCategoryId();
        Integer brandId = goodsWxListBO.getBrandId();
        Boolean isHot = goodsWxListBO.getIsHot();
        Boolean isNew = goodsWxListBO.getIsNew();
        String keyword = goodsWxListBO.getKeyword();
        String sort = goodsWxListBO.getSort();
        String order = goodsWxListBO.getOrder();
        Integer page = goodsWxListBO.getPage();
        Integer limit = goodsWxListBO.getLimit();

        PageHelper.startPage(page, limit);

        GoodsExample goodsExample = new GoodsExample();
        GoodsExample.Criteria criteria = goodsExample.createCriteria();
        if (categoryId != null && categoryId != 0) {
            criteria.andCategoryIdEqualTo(categoryId);
        }
        if (brandId != null) {
            criteria.andBrandIdEqualTo(brandId);
        }
        if (isHot != null) {
            criteria.andIsHotEqualTo(isHot);
        }
        if (isNew != null) {
            criteria.andIsNewEqualTo(isNew);
        }
        if (keyword != null && !"".equals(keyword)) {

            criteria.andNameLike("%" + keyword + "%");
        }
        if (sort != null && !"".equals(sort) && order != null && !"".equals(order)) {
            goodsExample.setOrderByClause(sort, order);
        }
        List<Goods> goods = goodsMapper.selectByExample(goodsExample);

        ArrayList<WxCategoryGoodsVO> list = new ArrayList<>();
        for (Goods good : goods) {
            WxCategoryGoodsVO vo = new WxCategoryGoodsVO();
            vo.setId(good.getId());
            vo.setBrief(good.getBrief());
            vo.setCounterPrice(good.getCounterPrice());
            vo.setIsHot(good.getIsHot());
            vo.setIsNew(good.getIsNew());
            vo.setName(good.getName());
            vo.setPicUrl(good.getPicUrl());
            vo.setRetailPrice(good.getRetailPrice());

            list.add(vo);
        }
        PageInfo<WxCategoryGoodsVO> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        //暂定为level = 2 的列表
        CategoryExample example = new CategoryExample();
        CategoryExample.Criteria criteria1 = example.createCriteria();
        criteria1.andLevelEqualTo("L2");

        List<Category> categoryList = categoryMapper.selectByExample(example);

        //TODO：以下代码完成历史搜索记录的录入工作；
        if (!StringUtils.isEmpty(keyword)) {
            SearchHistoryExample historyExample = new SearchHistoryExample();
            historyExample.createCriteria()
                    .andDeletedEqualTo(false)
                    .andKeywordEqualTo(keyword);
            List<SearchHistory> searchHistories = historyMapper.selectByExample(historyExample);
            if (searchHistories == null || searchHistories.size() == 0) {
                SearchHistory searchHistory = new SearchHistory();
                Date date = new Date();
                searchHistory.setDeleted(false);
                searchHistory.setKeyword(keyword);
                searchHistory.setAddTime(date);
                searchHistory.setFrom("search");

                //TODO：形参中加入userId后删除下面一行（）赋值语句
                Integer userId = id;

                searchHistory.setUserId(userId);
                searchHistory.setUpdateTime(date);
                historyMapper.insertSelective(searchHistory);
            }
        }
        //TODO：以上代码完成历史搜索记录的录入工作；

        return GoodsWxListVO.data(total, pages, limit, page, list, categoryList);

    }

    @Override
    public GoodsCategoryVO goodsCategory(Integer id) {
        GoodsCategoryVO goodsCategoryVO = new GoodsCategoryVO();
        //通过传入id查询该类目
        Category currentCategory = categoryMapper.selectByPrimaryKey(id);
        goodsCategoryVO.setCurrentCategory(currentCategory);
//由传入id查询父类类目id
        Integer pid = categoryMapper.selectWxPidByid(id);
        Category parentCategory = categoryMapper.selectByPrimaryKey(pid);
        goodsCategoryVO.setParentCategory(parentCategory);
        //由父id查询兄弟类目
        CategoryExample example = new CategoryExample();
        CategoryExample.Criteria criteria = example.createCriteria();
        criteria.andPidEqualTo(pid);
        List<Category> brotherCategory = categoryMapper.selectByExample(example);

        goodsCategoryVO.setBrotherCategory(brotherCategory);
        return goodsCategoryVO;
    }

    @Override
    public Integer goodsCount() {
        Integer i = goodsMapper.countGoods();
        return i;
    }

    @Override
    public GoodsWxRelatedVO goodsWxRelated(Integer id) {
        Integer page = 1;
        Integer limit = 6;
        String sort = "retail_price";
        String order = "asc";
        //查询该商品类目id
        PageHelper.startPage(page, limit);
        Integer CategoryId = goodsMapper.selectCategoryIdById(id);
        //通过类目id查询类似商品 以新品 人气推荐有限 价格升序 但去除本商品
        GoodsExample example = new GoodsExample();
        GoodsExample.Criteria criteria = example.createCriteria();
        criteria.andCategoryIdEqualTo(CategoryId);
        example.setOrderByClause(sort, order + " limit 0,6");
        List<Goods> goods = goodsMapper.selectByExample(example);
        ArrayList<WxCategoryGoodsVO> list = new ArrayList<>();
        for (Goods good : goods) {
            if (good.getId() != id) {
                WxCategoryGoodsVO vo = new WxCategoryGoodsVO();
                vo.setId(good.getId());
                vo.setName(good.getName());
                vo.setBrief(good.getBrief());
                vo.setPicUrl(good.getPicUrl());
                vo.setIsNew(good.getIsNew());
                vo.setRetailPrice(good.getRetailPrice());
                vo.setCounterPrice(good.getCounterPrice());
                list.add(vo);
            }
        }
        PageInfo<WxCategoryGoodsVO> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        return GoodsWxRelatedVO.data(total, pages, limit, page, list);
    }

    /**
     * 编辑时获取商品详情
     * 涉及表格：goods，attribute，specification，products，category（id和pid）
     *
     * @param goodsId
     * @return
     */
    @Override
    public GoodsDetailVO getGoodsDetail(Integer goodsId) {
        GoodsDetailVO goodsDetailVO = new GoodsDetailVO();

        //根据goodsId查询goods
        Goods goods = goodsMapper.selectByPrimaryKey(goodsId);

        //根据goodsId查询attributes
        GoodsAttributeExample goodsAttributeExample = new GoodsAttributeExample();
        GoodsAttributeExample.Criteria goodsAttributeExampleCriteria = goodsAttributeExample.createCriteria();
        goodsAttributeExampleCriteria.andGoodsIdEqualTo(goodsId);
        goodsAttributeExampleCriteria.andDeletedEqualTo(false);
        List<GoodsAttribute> goodsAttributes = goodsAttributeMapper.selectByExample(goodsAttributeExample);

        //根据goodsId查询specifications
        GoodsSpecificationExample goodsSpecificationExample = new GoodsSpecificationExample();
        GoodsSpecificationExample.Criteria goodsSpecificationExampleCriteria = goodsSpecificationExample.createCriteria();
        goodsSpecificationExampleCriteria.andGoodsIdEqualTo(goodsId);
        goodsSpecificationExampleCriteria.andDeletedEqualTo(false);
        List<GoodsSpecification> goodsSpecifications = goodsSpecificationMapper.selectByExample(goodsSpecificationExample);


        //根据goodsId查询products
        GoodsProductExample goodsProductExample = new GoodsProductExample();
        GoodsProductExample.Criteria goodsProductExampleCriteria = goodsProductExample.createCriteria();
        goodsProductExampleCriteria.andGoodsIdEqualTo(goodsId);
        goodsProductExampleCriteria.andDeletedEqualTo(false);
        List<GoodsProduct> goodsProducts = goodsProductMapper.selectByExample(goodsProductExample);

        //根据goodsId查询categoryIds
        List<Integer> categoryIds = new ArrayList<>();
        if (categoryIds != null && categoryIds.size() != 0) {
            Integer categoryId = goods.getCategoryId();
            Category category = categoryMapper.selectByPrimaryKey(categoryId);
            Integer pid = category.getPid();
            categoryIds.add(pid);
            categoryIds.add(categoryId);
        }

        //goodsDetailVO赋值
        goodsDetailVO.setGoods(goods);
        goodsDetailVO.setAttributes(goodsAttributes);
        goodsDetailVO.setCategoryIds(categoryIds);
        goodsDetailVO.setProducts(goodsProducts);
        goodsDetailVO.setSpecifications(goodsSpecifications);

        return goodsDetailVO;
    }

    /**
     * 商品编辑后进行提交修改
     * 涉及表格：goods，attribute，specification，products
     *
     * @param goodsUpdateBO
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void updateGoodsDetail(GoodsUpdateBO goodsUpdateBO) {

        //修改商品表；
        Goods goods = goodsUpdateBO.getGoods();
        Date date = new Date();
        goods.setUpdateTime(date);
        goodsMapper.updateByPrimaryKeySelective(goods);

        //修改attributes；
        //先将goodsId所有的attribute全部删掉,在进行插入；
        Integer goodsId = goods.getId();
        GoodsAttributeExample attributeExample = new GoodsAttributeExample();
        GoodsAttributeExample.Criteria attributeExampleCriteria = attributeExample.createCriteria();
        attributeExampleCriteria.andGoodsIdEqualTo(goodsId);
        goodsAttributeMapper.deleteByExample(attributeExample);

        List<GoodsAttribute> attributes = goodsUpdateBO.getAttributes();
        for (GoodsAttribute attribute : attributes) {
            goodsAttributeMapper.insertSelective(attribute);
        }

        //修改products;
        List<GoodsProduct> products = goodsUpdateBO.getProducts();
        for (GoodsProduct product : products) {
            goodsProductMapper.updateByPrimaryKeySelective(product);
        }

        //修改specifications
        List<GoodsSpecification> specifications = goodsUpdateBO.getSpecifications();
        for (GoodsSpecification specification : specifications) {
            goodsSpecificationMapper.updateByPrimaryKeySelective(specification);
        }
    }

    /**
     * 插入图片并返回图片id
     * 涉及表格：storage
     *
     * @param storage
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Integer insertStorage(Storage storage) {
        storageMapper.insertSelective(storage);
        Integer id = storage.getId();
        return id;

    }

    /**
     * 删除商品
     * 涉及表格：goods，attribute，specification，products
     *
     * @param goods
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteGoods(Goods goods) {
        Integer goodsId = goods.getId();
        goods.setDeleted(true);

        //修改商品的deleted为true
        goodsMapper.updateByPrimaryKeySelective(goods);

        //查询所有的attribute,并遍历修改deleted
        GoodsAttributeExample attributeExample = new GoodsAttributeExample();
        GoodsAttributeExample.Criteria attributeExampleCriteria = attributeExample.createCriteria();
        attributeExampleCriteria.andGoodsIdEqualTo(goodsId);
        List<GoodsAttribute> attributes = goodsAttributeMapper.selectByExample(attributeExample);

        for (GoodsAttribute attribute : attributes) {
            attribute.setDeleted(true);
            attribute.setId(null);
            goodsAttributeMapper.updateByExampleSelective(attribute, attributeExample);
        }

        //查询所有的specification,并遍历修改deleted
        GoodsSpecificationExample specificationExample = new GoodsSpecificationExample();
        GoodsSpecificationExample.Criteria specificationExampleCriteria = specificationExample.createCriteria();
        specificationExampleCriteria.andGoodsIdEqualTo(goodsId);
        List<GoodsSpecification> specifications = goodsSpecificationMapper.selectByExample(specificationExample);

        for (GoodsSpecification specification : specifications) {
            specification.setDeleted(true);
            specification.setId(null);
            goodsSpecificationMapper.updateByExampleSelective(specification, specificationExample);
        }


        //查询所有的product,并遍历修改deleted
        GoodsProductExample productExample = new GoodsProductExample();
        GoodsProductExample.Criteria productExampleCriteria = productExample.createCriteria();
        productExampleCriteria.andGoodsIdEqualTo(goodsId);
        List<GoodsProduct> products = goodsProductMapper.selectByExample(productExample);

        for (GoodsProduct product : products) {
            product.setDeleted(true);
            product.setId(null);
            goodsProductMapper.updateByExampleSelective(product, productExample);
        }


    }

    /**
     * 新增商品
     * 涉及表格：goods，attribute，specification，products
     *
     * @param goodsCreateBO
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void insertGoods(GoodsCreateBO goodsCreateBO) {
        //插入goods数据
        Goods goods = goodsCreateBO.getGoods();
        Date date = new Date();
        goods.setAddTime(date);
        goods.setUpdateTime(date);
        goodsMapper.insertSelective(goods);

        Integer goodsId = goods.getId();

        //插入attributes
        List<GoodsAttribute> attributes = goodsCreateBO.getAttributes();
        for (GoodsAttribute attribute : attributes) {
            attribute.setGoodsId(goodsId);
            goodsAttributeMapper.insertSelective(attribute);
        }

        //插入specifications
        List<GoodsSpecification> specifications = goodsCreateBO.getSpecifications();
        for (GoodsSpecification specification : specifications) {
            specification.setGoodsId(goodsId);
            goodsSpecificationMapper.insertSelective(specification);
        }

        //插入products
        List<GoodsProduct> products = goodsCreateBO.getProducts();
        for (GoodsProduct product : products) {
            product.setGoodsId(goodsId);
            goodsProductMapper.insertSelective(product);
        }

    }

    @Override
    public GoodsWxDetailVO goodsWxDetail(Integer id, Integer userID) {
        GoodsWxDetailVO goodsWxDetailVO = new GoodsWxDetailVO();
        GoodsAttributeExample example = new GoodsAttributeExample();
        GoodsAttributeExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(id);
        List<GoodsAttribute> attributes = goodsAttributeMapper.selectByExample(example);
        goodsWxDetailVO.setAttribute(attributes);
        Integer brandId = goodsMapper.selectBrandIdById(id);
        Brand brand = brandMapper.selectByPrimaryKey(brandId);
        if (brand == null) {
            goodsWxDetailVO.setBrand(new Brand());
        } else {
            goodsWxDetailVO.setBrand(brand);
        }

        GoodsWxDetailCommentVO commentVO = new GoodsWxDetailCommentVO();
        CommentExample example1 = new CommentExample();
        CommentExample.Criteria criteria1 = example1.createCriteria();
        criteria1.andValueIdEqualTo(id);
        long l = commentMapper.countByExample(example1);
        List<Comment> comments = commentMapper.selectByExample(example1);

        ArrayList<GoodsWxDetailCommentDataVO> vos = new ArrayList<>();
        if (comments.size() != 0) {
            Comment comment = comments.get(0);
            GoodsWxDetailCommentDataVO data = new GoodsWxDetailCommentDataVO();
            data.setAddTime(comment.getAddTime());
            data.setAdminContent(comment.getAdminContent());
            //通过查询用户id 再去查询user的微信昵称与昵称
            Integer userId = commentMapper.selectUserIdById(comment.getId());
            User user = userMapper.selectByPrimaryKey(userId);
            data.setAvatar(user.getAvatar());
            data.setContent(comment.getContent());
            data.setId(comment.getId());
            data.setNickname(user.getNickname());
            data.setPicList(comment.getPicUrls());
            vos.add(data);

            if (comments.size() > 1) {
                Comment comment1 = comments.get(1);
                GoodsWxDetailCommentDataVO data1 = new GoodsWxDetailCommentDataVO();
                data1.setAddTime(comment1.getAddTime());
                data1.setAdminContent(comment1.getAdminContent());
                //通过查询用户id 再去查询user的微信昵称与昵称
                Integer userId1 = commentMapper.selectUserIdById(comment1.getId());
                User user1 = userMapper.selectByPrimaryKey(userId1);
                data1.setAvatar(user1.getAvatar());
                data1.setContent(comment1.getContent());
                data1.setId(comment1.getId());
                data1.setNickname(user1.getNickname());
                data1.setPicList(comment1.getPicUrls());
                vos.add(data1);
            }
        }
        commentVO.setCount((int) l);
        commentVO.setData(vos);
        goodsWxDetailVO.setComment(commentVO);

        //TODO:GROUPON暂时未定
        Groupon[] groupons = new Groupon[0];
        goodsWxDetailVO.setGroupon(groupons);

        Goods goods = goodsMapper.selectByPrimaryKey(id);
        goodsWxDetailVO.setInfo(goods);

        IssueExample example2 = new IssueExample();
        List<Issue> list = issueMapper.selectByExample(example2);
        goodsWxDetailVO.setIssue(list);

        GoodsProductExample example3 = new GoodsProductExample();
        GoodsProductExample.Criteria criteria2 = example3.createCriteria();
        criteria2.andGoodsIdEqualTo(id);
        List<GoodsProduct> products = goodsProductMapper.selectByExample(example3);
        goodsWxDetailVO.setProductList(products);

        //TODO:分享暂时定为false
        Boolean share = false;
        goodsWxDetailVO.setShare(share);

        String shareImage = "";
        goodsWxDetailVO.setShareImage(shareImage);

        GoodsSpecificationExample example4 = new GoodsSpecificationExample();
        GoodsSpecificationExample.Criteria criteria3 = example4.createCriteria();
        criteria3.andGoodsIdEqualTo(id);
        List<GoodsSpecification> goodsSpecifications = goodsSpecificationMapper.selectByExample(example4);
        ArrayList<GoodsWxDetailSpecVO> vos1 = new ArrayList<>();
        GoodsWxDetailSpecVO vo1 = new GoodsWxDetailSpecVO();
        vo1.setName("规格");
        List<GoodsSpecification> list1 = new ArrayList<>();
        GoodsWxDetailSpecVO vo2 = new GoodsWxDetailSpecVO();
        vo2.setName("颜色");
        ArrayList<GoodsSpecification> list2 = new ArrayList<>();

        for (GoodsSpecification goodsSpecification : goodsSpecifications) {
            if (goodsSpecification.getSpecification().equals("规格")) {
                list1.add(goodsSpecification);
            }
            if (goodsSpecification.getSpecification().equals("颜色")) {
                list2.add(goodsSpecification);
            }
        }
        vo1.setValueList(list1);
        vo2.setValueList(list2);
        vos1.add(vo1);
        if (vo2.getValueList().size() != 0) {
            vos1.add(vo2);
        }
        goodsWxDetailVO.setSpecificationList(vos1);

        //判断是否收藏

        CollectExample collectExample = new CollectExample();
        CollectExample.Criteria criteria4 = collectExample.createCriteria();
        criteria4.andValueIdEqualTo(id);
        criteria4.andUserIdEqualTo(userID);
        long hasCollect = collectMapper.countByExample(collectExample);
        Integer userHadCollect = 0;
        if (hasCollect != 0) {
           userHadCollect = 1;
        }
        goodsWxDetailVO.setUserHasCollect(userHadCollect);

        return goodsWxDetailVO;
    }
}
